﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace WebBanHang
{
    public class AutoIncrease
    {
        public static string AutoIncStr(DataTable dt, string ColumnName, string prefix)
        {
            if (dt.Rows.Count == 0)
            {
                return prefix + "00000";
            }
            DataRow row = dt.Rows[dt.Rows.Count - 1];
            // lay vi tri cuoi cung
            string s_Ma = row[ColumnName].ToString();
            int i_ma = Convert.ToInt32(s_Ma.Replace(prefix, "")) + 1;
            string zero = "";
            if (i_ma < 10)
            {
                zero = "0000";
            }
            else if (i_ma < 100)
            {
                zero = "000";
            }
            else if (i_ma < 1000)
            {
                zero = "00";
            }
            else if (i_ma < 10000)
            {
                zero = "0";
            }
            s_Ma = prefix + zero + i_ma;
            return s_Ma;
        }

        public static int AutoIncInt(DataTable dt, string ColumnName)
        {
            if (dt.Rows.Count == 0)
            {
                return 0;
            }
            // lay vi tri cuoi cung
            DataRow row = dt.Rows[dt.Rows.Count - 1];
            int ma = Convert.ToInt32(row[ColumnName]) + 1;
            return ma;
        }
    }
}